﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using Styx.Common;
using Styx.CommonBot.Routines;
using Styx;
using Styx.CommonBot;

namespace FrostMage
{
    public class toNyxMage : CombatRoutine
    {
        
        public override sealed string Name { get { return "LazyRaider FrostMage by toNyx (manual targetting)"; } }
        public override WoWClass Class { get { return WoWClass.Mage; } }
        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        public override bool WantButton{ get { return true; } }
        public override void OnButtonPress() { var myGUI = new FrostMageGUI(); myGUI.Show(); }

        public static void toNyxLog(string message, params object[] args) { Logging.Write("[toNyxDEBUG] " + message, args); }

        #region CONSTANT AND VARIABLES

        //START OF CONSTANTS ==============================

        // SPELLSTEALING, USING BUFFS FROM RAIDS!, NO DUNGEONS IDs HERE CARE ! /!\
        private readonly Dictionary<int, String> StealBuffs = new Dictionary<int, String>
                                                                  {
                                                                       {117309, "Cleansing Waters"}
                                                                  };

        //START OF SPELLS AND AURAS ==============================

        // AURAS & PROCS

        // -- FRIENDLY
        private const string ARCANE_BRILLANCE = "Arcane Brilliance";
        private const string FROST_ARMOR = "Frost Armor";

        // -- OFFENSIVE
        private const string FINGER_OF_FROST = "Fingers of Frost";
        private const string BRAIN_FREEZE = "Brain Freeze";
        private const string EVOCATION_BUFF = "Invoker's Energy";

        // UTILITY
        private const string COUNTERSPELL = "Counterspell";
        private const string POLYMORPH = "Polymorph";
        private const string SPELLSTEAL = "Spellsteal";
        private const string REMOVE_CURSE = "Remove Curse";
        private const string EVOCATION = "Evocation";
        private const string RUNE_OF_POWER = "Rune of Power";
        private const string ICE_BARRIER = "Ice Barrier";
        private const string SUMMON_WATER_ELEMENTAL = "Summon Water Elemental";
        private const string CONJURE_REFRESHMENT = "Conjure Refreshment";
        private const string CONJURE_MANA_GEM = "Conjure Mana Gem";
        private const string MANA_GEM = "Mana Gem";
        private const string HEALTH_STONE = "Healthstone";

        // FIGHTINGUUUUUU
        private const string FROSTFIRE_BOLT = "Frostfire Bolt";
        private const string FROST_BOLT = "Frostbolt";
        private const string ICE_LANCE = "Ice Lance";
        private const string ICY_VEINS = "Icy Veins"; 
        private const string MIRROR_IMAGE = "Mirror Image";
        private const string ALTER_TIME = "Alter Time";
        private const string FLAMESTRIKE = "Flamestrike";
        private const string BLIZZARD = "Blizzard";
        private const string FROZEN_ORB = "Frozen Orb";
        private const string NETHER_TEMPEST = "Nether Tempest";
        private const string FROST_BOMB = "Frost Bomb";

        // SLACKINGUUUUU
        private const string ICE_BLOCK = "Ice Block";

       
        //END OF SPELLS AND AURAS ==============================

        //END OF CONSTANTS ==============================

        //START OF CUSTOM VARS
        public string LastSpell = "";
        public WoWUnit NearestTank = null;
        public WoWUnit GetTankTarget = null;
        public static bool HaveFood { get { return StyxWoW.Me.BagItems.Any(item => item.Entry == 80610); } }
        private static bool HaveManaGem { get { return StyxWoW.Me.BagItems.Any(i => i.Entry == 36799 || i.Entry == 81901); } }
        private static bool HaveHealthStone { get { return StyxWoW.Me.BagItems.Any(i => i.Entry == 5512); } }

        #endregion

        public override void Initialize()
        {
            toNyxLog("Combat Routine Loaded... It's raping time!");
            Hotkeys_Init();
        }

        #region Resting

            public override bool NeedRest
            {
                get { return Me.HealthPercent <= 65 && Me.IsAlive; }
            }

            public override void Rest()
            {
                if (NeedRest)
                     Styx.CommonBot.Rest.Feed();
            }

        #endregion

        #region Pull Buffs

            public override bool NeedPullBuffs { get { return false; } }

            public override void PullBuff() { }

        #endregion

        #region Pre Combat Buffs

            public override bool NeedPreCombatBuffs { get { return true; } }

            public override void PreCombatBuff()
            {
                WaterElemental();
                ConjureFood();
                MakeManaGem();
                FrostArmor();
                ArcaneBrilliance();
            }

        #endregion

        #region Combat Buffs

            public override bool NeedCombatBuffs { get { return false; } }

            public override void CombatBuff() { }

        #endregion

        #region Heal

        public override bool NeedHeal { get { return false; } }

        public override void Heal() { }

        #endregion

        #region Falling

        public void HandleFalling() { }

        #endregion

        #region Combat

            public override void Combat()
            {
                Facing();

                // Check for forgotten PreCombatBuff
                FrostArmor();
                ArcaneBrilliance();
                WaterElemental();

                // Mana Gem
                UseManaGem();

                // Defensive checks
                IceBlock();
                IceBarrier();
                UseHealthStone();

                // Talents Checks
                Evocation();
                RuneOfPower();

                // Priority spells
                Polymorph();
                CounterSpell();
                SpellSteal();
                Decursing();
                MirrorImage();
                IcyVeins();
                AlterTime();
                FingersOfFrost();
                BrainFreeze();
                FrozenOrb();
                NetherTempest();
                FrostBomb();

                // Check for AOE Routine
                
                if(toNyxMageSettings.Instance.EnableAOE)
                {
                    if (Adds())
                        FrozenOrbAOE();
                    if (Adds())
                        FlameStrike();
                    if (Adds())
                        Blizzard();                   
                }

                FrostBolt();
            }

        #endregion

        #region Spells

            // BUFFS

            public bool ArcaneBrilliance()
            {
                if (SpellManager.CanCast(ARCANE_BRILLANCE) && !Me.HasAura(ARCANE_BRILLANCE) && LastSpell != ARCANE_BRILLANCE && !Me.Mounted)
                {
                    SpellManager.Cast(ARCANE_BRILLANCE);
                    toNyxLog(ARCANE_BRILLANCE);
                    LastSpell = ARCANE_BRILLANCE;
                    StyxWoW.SleepForLagDuration();
                    return true;
                }
                return false;
            }

            public bool FrostArmor()
            {
                if (SpellManager.CanCast(FROST_ARMOR) && !Me.HasAura(FROST_ARMOR) && LastSpell != FROST_ARMOR && !Me.IsCasting && !Me.Mounted)
                {
                    SpellManager.Cast(FROST_ARMOR);
                    toNyxLog(FROST_ARMOR);
                    LastSpell = FROST_ARMOR;
                    StyxWoW.SleepForLagDuration();
                    return true;
                }
                return false;
            }

            // TALENT BASED

            public bool Evocation()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.UseEvocation) return false;

                bool BasicEvocationConditions = Me.Combat && SpellManager.CanCast(EVOCATION) && !Me.IsMoving;
                bool AdditionnalEvocationConditions = false;

                if (toNyxMageSettings.Instance.KeepEvocationBuff)
                    AdditionnalEvocationConditions = !Me.HasAura(EVOCATION_BUFF);
                
                if (toNyxMageSettings.Instance.EvocBelowThreshold)
                    AdditionnalEvocationConditions = Me.ManaPercent < toNyxMageSettings.Instance.EvocThresholdMP;

                if (BasicEvocationConditions && AdditionnalEvocationConditions)
                {
                    toNyxLog(EVOCATION);
                    SpellManager.Cast(EVOCATION);
                    LastSpell = EVOCATION;
                    return true;
                }
                return false;
            }

            public bool RuneOfPower()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.UseRoP) return false;

                if (!Me.IsMoving && LastSpell != RUNE_OF_POWER && !Me.HasAura(RUNE_OF_POWER) && Me.Combat && SpellManager.CanCast(RUNE_OF_POWER))
                {
                    toNyxLog(RUNE_OF_POWER);
                    SpellManager.Cast(RUNE_OF_POWER);
                    LastSpell = RUNE_OF_POWER;
                    return SpellManager.ClickRemoteLocation(Me.Location);
                }

                return false;

            }

            // OFFENSIVE

            public bool FrostBolt()
            {
                if (Me.CurrentTarget == null) return false;
                if (Me.Combat && SpellManager.CanCast(FROST_BOLT) && !Me.IsCasting && !Me.Mounted)
                {
                    toNyxLog(FROST_BOLT);
                    SpellManager.Cast(FROST_BOLT);
                    LastSpell = FROST_BOLT;
                    return true;
                }
                return false;
            }

            public bool FrostBomb()
            {
                if (Me.CurrentTarget == null) return false;
                if (SpellManager.CanCast(FROST_BOMB))
                {
                    toNyxLog(FROST_BOMB);
                    SpellManager.Cast(FROST_BOMB);
                    LastSpell = FROST_BOMB;
                    return true;
                }
                return false;
            }

            public bool FrozenOrb()
            {
                if (Me.CurrentTarget == null) return false;
                if (!Me.Mounted)
                {
                    if (SpellManager.CanCast(FROZEN_ORB) && GetSpellCooldown(FROZEN_ORB).TotalSeconds < 1 && IsTargetBoss())
                    {
                        toNyxLog(FROZEN_ORB);
                        SpellManager.Cast(FROZEN_ORB);
                        LastSpell = FROZEN_ORB;
                        return true;
                    }
                }
                return false;
            }

            public bool FingersOfFrost()
            {
                if (Me.CurrentTarget == null) return false;
                if (Me.HasAura(FINGER_OF_FROST) && !Me.Mounted && !Me.IsCasting)
                {
                    uint IceLanceCounter = Me.Auras[FINGER_OF_FROST].StackCount;
                    toNyxLog(FINGER_OF_FROST + " (" + IceLanceCounter + " time(s))");

                    while (IceLanceCounter > 0)
                    {
                        SpellManager.Cast(ICE_LANCE);
                        IceLanceCounter--;
                    }

                    LastSpell = ICE_LANCE;
                    return true;

                }
                return false;
            }

            public bool BrainFreeze()
            {
                if (Me.CurrentTarget == null) return false;
                if (Me.HasAura(BRAIN_FREEZE) && !Me.Mounted && !Me.IsCasting)
                {
                    toNyxLog(FROSTFIRE_BOLT);
                    SpellManager.Cast(FROSTFIRE_BOLT);
                    LastSpell = FROSTFIRE_BOLT;
                    return true;
                }
                return false;
            }

            public bool NetherTempest()
            {
                if (Me.CurrentTarget == null) return false;
                if (SpellManager.CanCast(NETHER_TEMPEST) && !Me.Mounted && !Me.CurrentTarget.HasAura(NETHER_TEMPEST) && LastSpell != NETHER_TEMPEST && MyAuraTimeLeft(NETHER_TEMPEST, Me.CurrentTarget) < 1000 && Me.CurrentTarget.InLineOfSpellSight && MyAuraTimeLeft(NETHER_TEMPEST, Me.CurrentTarget) < 1000 && !Me.IsChanneling)
                {
                    SpellManager.Cast(NETHER_TEMPEST);
                    toNyxLog(NETHER_TEMPEST);
                    LastSpell = NETHER_TEMPEST;
                    return true;
                }
                return false;
            }

            // OFFENSIVE AoE

            public bool FlameStrike()
            {
                if (Me.CurrentTarget == null) return false;
                if (toNyxMageSettings.Instance.UseFlameStrike && SpellManager.CanCast(FLAMESTRIKE) && !Me.Mounted && GetSpellCooldown(FLAMESTRIKE).TotalSeconds < 1 && !Me.IsChanneling)
                {
                    SpellManager.Cast(FLAMESTRIKE);
                    SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
                    toNyxLog(FLAMESTRIKE);
                    LastSpell = FLAMESTRIKE;
                    return true;
                }
                return false;
            }

            public bool FrozenOrbAOE()
            {
                if (Me.CurrentTarget == null) return false;
                if (SpellManager.CanCast(FROZEN_ORB) && GetSpellCooldown(FROZEN_ORB).TotalSeconds < 1 && !Me.IsChanneling && !Me.Mounted)
                {
                    SpellManager.Cast(FROZEN_ORB);
                    toNyxLog(FROZEN_ORB);
                    LastSpell = FROZEN_ORB;
                    return true;
                }
                return false;
            }

            public bool Blizzard()
            {
                if (Me.CurrentTarget == null) return false;
                if (toNyxMageSettings.Instance.UseBlizzard && SpellManager.CanCast(BLIZZARD) && GetSpellCooldown(BLIZZARD).TotalSeconds < 1 && Me.CurrentTarget.Distance > 8 && !Me.Mounted)
                {
                    SpellManager.Cast(BLIZZARD);
                    SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
                    toNyxLog(BLIZZARD);
                    LastSpell = BLIZZARD;
                    return true;
                }
                return false;
            }

            // COOLDOWNS

            public bool IcyVeins()
            {
                if (!IsTargetBoss()) return false;
                if (SpellManager.CanCast(ICY_VEINS) && GetSpellCooldown(ICY_VEINS).TotalSeconds < 1 && IsTargetBoss() && !Me.Mounted)
                {
                    SpellManager.Cast(ICY_VEINS);
                    toNyxLog(ICY_VEINS);
                    LastSpell = ICY_VEINS;
                    return true;
                }
                return false;
            }

            public bool MirrorImage()
            {
                if (!IsTargetBoss()) return false;
                if (SpellManager.CanCast(MIRROR_IMAGE) && GetSpellCooldown(MIRROR_IMAGE).TotalSeconds < 1 && IsTargetBoss() && !Me.Mounted)
                {
                    SpellManager.Cast(MIRROR_IMAGE);
                    toNyxLog(MIRROR_IMAGE);
                    LastSpell = MIRROR_IMAGE;
                    return true;
                }
                return false;
            }

            public bool AlterTime()
            {
                if (!IsTargetBoss()) return false;
                if (SpellManager.CanCast(ALTER_TIME) && Me.HasAura(BRAIN_FREEZE) && Me.HasAura(FINGER_OF_FROST))
                {
                    toNyxLog(ALTER_TIME);
                    return SpellManager.Cast(ALTER_TIME);
                }

                return false;
            }

            // DEFENSIVE

            public bool IceBlock()
            {
                if (toNyxMageSettings.Instance.UseIceBlock)
                {
                    if (Me.Combat && SpellManager.CanCast(ICE_BLOCK) && Me.HealthPercent < toNyxMageSettings.Instance.IceBlockHP && !StyxWoW.Me.ActiveAuras.ContainsKey("Hypothermia"))
                    {
                        toNyxLog(ICE_BLOCK);
                        SpellManager.Cast(ICE_BLOCK);
                        LastSpell = ICE_BLOCK;
                        return true;
                    }
                }
                return false;
            }

            public bool UseHealthStone()
            {
                if (!toNyxMageSettings.Instance.UseHealthStone) return false;

                if (Me.Combat && HaveHealthStone)
                {
                    WoWItem myStone = StyxWoW.Me.BagItems.First(i => i.Entry == 5512);
                    if (myStone.CooldownTimeLeft.TotalSeconds < 1 && Me.HealthPercent < toNyxMageSettings.Instance.HealthStoneHP && !Me.Mounted)
                    {
                        myStone.Use();
                        toNyxLog(HEALTH_STONE);
                        LastSpell = "Health Stone";
                        return true;
                    }
                }

                return false;
            }

            public bool IceBarrier()
            {
                if (!toNyxMageSettings.Instance.UseIceBarrier) return false;

                if (Me.Combat && !Me.HasAura(ICE_BARRIER) && SpellManager.CanCast(ICE_BARRIER) && GetSpellCooldown(ICE_BARRIER).TotalSeconds < 1 && !Me.Mounted)
                {
                    SpellManager.Cast(ICE_BARRIER);
                    toNyxLog(ICE_BARRIER);
                    LastSpell = ICE_BARRIER;
                    return true;

                }

                return false;
            }
           
            // UTILITY

            public bool Polymorph()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.UsePolymorphOnFocus) return false;

                WoWUnit focus = Me.FocusedUnit;

                // SETTINGS CHECK
                if (focus != null)
                {
                    if (toNyxMageSettings.Instance.DisablePolymorphOnBosses && IsFocusBoss()) return false;

                    if (!focus.HasAura(POLYMORPH) || focus.GetAuraByName(POLYMORPH).Duration <= 10)
                    {
                            if ((focus.IsBeast || focus.IsHumanoid)
                                && focus.Attackable
                                && focus.InLineOfSpellSight
                                && (focus.Distance - focus.CombatReach -1)  <= 3
                                && SpellManager.CanCast(POLYMORPH,focus))
                            {
                            toNyxLog(POLYMORPH + "on " + focus.Name);
                            SpellManager.Cast(POLYMORPH, focus);
                            }                         
                    }                     
                }
                           
                
                return false;
            }

            public bool CounterSpell()
            {
                if (Me.CurrentTarget == null) return false;

                WoWUnit myTarget = Me.CurrentTarget;

                if (GetSpellCooldown(COUNTERSPELL).TotalSeconds < 1 
                    && SpellManager.CanCast(COUNTERSPELL)
                    && myTarget != null)
                {
                    if ((myTarget.IsCasting || myTarget.IsCastingHealingSpell)
                    && myTarget.CanInterruptCurrentSpellCast
                    && !Me.Mounted)
                    {
                        toNyxLog(COUNTERSPELL + " on " + myTarget.Name);
                        SpellManager.Cast(COUNTERSPELL, myTarget);
                        LastSpell = COUNTERSPELL;
                        return true;                        
                    }
                }
                return false;
            }
            
            public bool SpellSteal()
            {
                if (Me.CurrentTarget == null) return false;

                if (IsTargetBoss())
                {
                    WoWUnit myTarget;

                    if (Me.FocusedUnit != null && Me.FocusedUnit.Attackable && Me.FocusedUnit.Distance - Me.FocusedUnit.CombatReach - 1 <= 30 && Me.FocusedUnit.InLineOfSpellSight)
                        myTarget = Me.FocusedUnit;
                    else
                        myTarget = Me.CurrentTarget;

                    if (myTarget != null && SpellManager.CanCast(SPELLSTEAL) && StyxWoW.Me.ManaPercent > 40)
                    {
                        using (StyxWoW.Memory.AcquireFrame())
                        {
                            foreach (KeyValuePair<int, string> spell in StealBuffs.Where(spell => myTarget.ActiveAuras.ContainsKey(spell.Key.ToString(CultureInfo.InvariantCulture))))
                            {
                                toNyxLog(SPELLSTEAL + "( " + spell.Value + " ) on " + myTarget.Name);
                                SpellManager.Cast(SPELLSTEAL, myTarget);
                                LastSpell = SPELLSTEAL;
                                return true;
                            }

                        }                        
                    }

                    return false;
                }
                return false;
            }

            public bool Decursing()
            {
                if (toNyxMageSettings.Instance.UseDecurse && SpellManager.CanCast(REMOVE_CURSE))
                {
                    WoWPlayer player = GetDecurseTarget(40f);

                    if (player != null && player.Distance - player.CombatReach - 1 <= 40f && player.InLineOfSight)
                    {
                        toNyxLog(REMOVE_CURSE + " on " + player.Name + " [ " + player.Class + " ]");
                        return SpellManager.Cast(REMOVE_CURSE, player);
                    }
                }
                return false;
            }
            
            public bool WaterElemental()
            {
                if (GetSpellCooldown(SUMMON_WATER_ELEMENTAL).TotalSeconds < 1 && !Me.GotAlivePet  && LastSpell != SUMMON_WATER_ELEMENTAL && !Me.Mounted)
                {
                    toNyxLog(SUMMON_WATER_ELEMENTAL);
                    SpellManager.Cast(SUMMON_WATER_ELEMENTAL);
                    LastSpell = SUMMON_WATER_ELEMENTAL;
                    return true;
                }
                return false;
            }
           
            public bool ConjureFood()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.ConjureFood) return false;

                if (!Me.Mounted && !Me.IsCasting)
                {
                    if (!HaveFood)
                    {
                        if (SpellManager.CanCast(CONJURE_REFRESHMENT) && LastSpell != CONJURE_REFRESHMENT)
                        {
                            SpellManager.Cast(CONJURE_REFRESHMENT);
                            toNyxLog(CONJURE_REFRESHMENT);
                            
                            LastSpell = CONJURE_REFRESHMENT;
                            return true;
                        }                         
                    }
                }
                return false;
            }
            
            public bool MakeManaGem()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.UseManaGem) return false;

                if (!Me.Mounted && !Me.IsCasting)
                {
                    if(!HaveManaGem)
                    {
                        if (SpellManager.CanCast(CONJURE_MANA_GEM) && LastSpell != CONJURE_MANA_GEM)
                        {
                            SpellManager.Cast(CONJURE_MANA_GEM);
                            toNyxLog(CONJURE_MANA_GEM);
                            LastSpell = CONJURE_MANA_GEM;
                            return true;
                        }                        
                    }
                }
                return false;
            }

            public bool UseManaGem()
            {
                // SETTINGS CHECK
                if (!toNyxMageSettings.Instance.UseManaGem) return false;

                if (Me.Combat && HaveManaGem)
                {
                    WoWItem myGem = StyxWoW.Me.BagItems.First(i => i.Entry == 36799 || i.Entry == 81901);
                    if (myGem.CooldownTimeLeft.TotalSeconds < 1 && Me.ManaPercent <= toNyxMageSettings.Instance.ManaGemMP && !Me.Mounted)
                    {
                        myGem.Use();
                        toNyxLog(MANA_GEM);
                        LastSpell = "Mana Gem";
                        return true;
                    }
                }

                return false;
            }
      
        #endregion

        #region SpellsCooldownsManagement

            public static TimeSpan GetSpellCooldown(string spell)
            {
                SpellFindResults results;
                if (SpellManager.FindSpell(spell, out results))
                {
                    if (results.Override != null)
                        return results.Override.CooldownTimeLeft;
                    return results.Original.CooldownTimeLeft;
                }
                return TimeSpan.MaxValue;
            }

        #endregion
 
        #region MyAuraTimeLeft

            public double MyAuraTimeLeft(string auraName, WoWUnit u)
            {
                using (StyxWoW.Memory.AcquireFrame())
                {
                    if (u == null || !u.IsValid || !u.IsAlive)
                        return 0;

                    WoWAura aura = u.GetAllAuras().FirstOrDefault(a => a.Name == auraName && a.CreatorGuid == Me.Guid);

                    if (aura == null)
                        return 0;

                    return aura.TimeLeft.TotalMilliseconds;
                }
            }

            public double MyAuraTimeLeft(int auraID, WoWUnit u)
            {
                using (StyxWoW.Memory.AcquireFrame())
                {
                    if (u == null || !u.IsValid || !u.IsAlive)
                        return 0;

                    WoWAura aura = u.GetAllAuras().FirstOrDefault(a => a.SpellId == auraID && a.CreatorGuid == Me.Guid);

                    if (aura == null)
                        return 0;

                    return aura.TimeLeft.TotalMilliseconds;
                }
            }

        #endregion   
 
        #region FacingManagement

            public void Facing()
            {
                if (Me.CurrentTarget == null || Me.CurrentTarget.IsDead) return;
                if (Me.CurrentTarget.InLineOfSpellSight && !Me.IsMoving)
                {
                    Me.CurrentTarget.Face();
                }
            }

        #endregion

        #region TargetChecks

            private bool IsTargetBoss()
            {
                if (Me.CurrentTarget == null) return false;
                if (Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.WorldBoss)
                    return true;
                if (Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite && Me.CurrentTarget.MaxHealth >= 5000000)
                    return true;
                if (Me.CurrentTarget.CreatureRank == WoWUnitClassificationType.Elite && Me.CurrentTarget.Level >= Me.Level && (!Me.GroupInfo.IsInParty || !Me.IsInInstance))
                    return true;
                if (Me.CurrentTarget.Name.Contains("Training Dummy"))
                    return true;

                return false;
            }

            private bool IsFocusBoss()
            {
                if (Me.FocusedUnit == null) return false;
                if (Me.FocusedUnit.CreatureRank == WoWUnitClassificationType.WorldBoss)
                    return true;
                if (Me.FocusedUnit.CreatureRank == WoWUnitClassificationType.Elite && Me.FocusedUnit.MaxHealth >= 5000000)
                    return true;
                if (Me.FocusedUnit.CreatureRank == WoWUnitClassificationType.Elite && Me.FocusedUnit.Level >= Me.Level && (!Me.GroupInfo.IsInParty || !Me.IsInInstance))
                    return true;
                if (Me.FocusedUnit.Name.Contains("Training Dummy"))
                    return true;

                return false;
            }

            public static bool IsEnemy(WoWUnit u)
            {
                if (u == null || !u.CanSelect || !u.Attackable || !u.IsAlive || u.IsNonCombatPet || u.IsCritter)
                    return false;

                if (!u.IsPlayer)
                    return u.IsHostile || u.Aggro || u.PetAggro || (!Me.IsInInstance && u.Name.Contains("Dummy"));

                WoWPlayer p = u.ToPlayer();
                if (p != null)
                    return p.IsHorde != StyxWoW.Me.IsHorde;

                return false;
            }

            public WoWPlayer GetDecurseTarget(double range)
            {
                return (from unit in ObjectManager.GetObjectsOfTypeFast<WoWPlayer>()
                        orderby unit.HealthPercent ascending
                        where (!unit.IsDead
                        && !unit.IsGhost
                        && unit.Distance - unit.CombatReach - 1 <= range
                        && unit.InLineOfSpellSight
                        && unit.ActiveAuras.Any(a => a.Value.IsHarmful && a.Value.Spell.DispelType == WoWDispelType.Curse)
                        && (unit.IsInMyPartyOrRaid || unit.Guid == Me.Guid))
                        select unit).FirstOrDefault();
            }

        #endregion
   
        #region AddCounting

            public static bool Adds()
            {
                List<WoWUnit> mobList = ObjectManager.GetObjectsOfType<WoWUnit>(false).FindAll(unit =>
                        Me.GotTarget
                        && unit.IsAlive
                        && unit.Guid != Me.Guid
                        && !unit.IsFriendly
                        && unit.IsHostile
                        && unit.Attackable
                        && !unit.IsTotem
                        && !unit.IsCritter
                        && !unit.IsNonCombatPet
                        && (unit.Location.Distance(Me.CurrentTarget.Location) <= 10 || unit.Location.Distance2D(Me.CurrentTarget.Location) <= 10));

                return mobList.Count >= toNyxMageSettings.Instance.MinimumEnemiesAOE;

            }

        #endregion addCounting

        #region Hotkeys

            public static ModifierKeys GetModifierKey(string value)
            {
                switch (value)
                {
                    case "Ctrl":
                        return ModifierKeys.Control;
                    case "Shift":
                        return ModifierKeys.Shift;
                    case "Alt":
                        return ModifierKeys.Alt;
                    case "Win":
                        return ModifierKeys.Win;
                }

                return ModifierKeys.NoRepeat;
            }

            public static Keys GetHotkey(string value)
            {
                switch (value)
                {
                    case "F1":
                        return Keys.F1;
                    case "F2":
                        return Keys.F2;
                    case "F3":
                        return Keys.F3;
                    case "F4":
                        return Keys.F4;
                }

                return Keys.None;
            }

            public static void Hotkeys_Init()
            {
                if (!toNyxMageSettings.Instance.EnableHotKeys)
                {
                    if (HotkeysManager.Hotkeys.Any())
                    {
                        var myHKs = new List<string>();
                           
                        toNyxLog("Removing Hotkeys, please wait...");

                        myHKs.AddRange(HotkeysManager.Hotkeys.Select(hotkey => hotkey.Name));

                        foreach (var myHK in myHKs)
                        {
                            HotkeysManager.Unregister(myHK);
                            toNyxLog(myHK + " Bind now removed/unregistered");  
                        }             
                    }
                }
                else
                {
                    // AOE HotKey

                    if(toNyxMageSettings.Instance.AoEHotKey != "None" && HotkeysManager.Hotkeys.All(hk => hk.Name != "AOE"))
                    {
                        HotkeysManager.Register("AOE", GetHotkey(toNyxMageSettings.Instance.AoEHotKey), GetModifierKey(toNyxMageSettings.Instance.HotKeyModifier), hk => AOE_Toggle());
                        if (toNyxMageSettings.Instance.HotKeyModifier != "None")
                            toNyxLog("AOE Bind now ready, press {0} + {1} to enable/disable AOE spells", toNyxMageSettings.Instance.HotKeyModifier, toNyxMageSettings.Instance.AoEHotKey);
                        else
                            toNyxLog("AOE Bind now ready, press {0} to enable/disable AOE spells", toNyxMageSettings.Instance.AoEHotKey);

                    }                    
                }
            }

            private static void AOE_Toggle()
            {
                toNyxMageSettings.Instance.EnableAOE = !toNyxMageSettings.Instance.EnableAOE;
                toNyxLog("AoE Rotation Enabled : " + toNyxMageSettings.Instance.EnableAOE);
                toNyxMageSettings.Instance.Save();
            }

        #endregion

    }
}
